/**
 * SCRIPTS FOR VOTING MANAGEMENT
 */

	/* VOTE ITEM CATEGORY */
	
		//-- DELETE
		function deleteCategory(url_execute){
			if(confirm("Are you sure you want to delete this category?")){
				window.location=url_execute;
			}else{
				return false;
			}
		}
		//-- ADD
		function addCategory(url_execute){
			var cat_desc=document.getElementById('txtcat').value;
			if(cat_desc==''){
				alert('Please enter category name');
				document.getElementById('txtcat').focus();
				return false;
			}
				document.forms[0].action=url_execute;
				document.forms[0].submit();
		}
		//-- UPDATE
		function updateCategory(url_execute){
			var cat_desc=document.getElementById('txtcat').value;
			if(cat_desc==''){
				alert('Please enter category name');
				document.getElementById('txtcat').focus();
				return false;
			}
				document.forms[0].action=url_execute;
				document.forms[0].submit();
		}
		
		
		
		/* VOTE ITEM */
		
		//-- DELETE
		function deleteItem(url_execute){
			if(confirm("Are you sure you want to delete this item?")){
				window.location=url_execute;
			}else{
				return false;
			}
		}
		//-- ADD
		function addItem(url_execute){
			var item_desc=document.getElementById('txtitem').value;
			if(item_desc==''){
				alert('Please enter item description');
				document.getElementById('txtitem').focus();
				return false;
			}
				document.forms[0].action=url_execute;
				document.forms[0].submit();
		}
		//-- UPDATE
		function updateItem(url_execute){
			var item_desc=document.getElementById('txtitem').value;
			if(item_desc==''){
				alert('Please enter item name');
				document.getElementById('txtitem').focus();
				return false;
			}
				document.forms[0].action=url_execute;
				document.forms[0].submit();
		}
		
		
		/* VOTE TOPIC */
		
		//-- DELETE
		function deleteTopic(url_execute){
			if(confirm("Are you sure you want to delete this topic?")){
				window.location=url_execute;
			}else{
				return false;
			}
		}
		//-- ADD
		function addTopic(url_execute){
			var top_name=document.getElementById('txttopname').value;
			var top_desc=document.getElementById('txttopdesc').value;
			var max_item=document.getElementById('txtmax').value;
			if(top_name==''){
				alert('Please enter topic name');
				document.getElementById('txttopname').focus();
				return false;
			}
			if(top_desc==''){
				alert('Please enter topic description');
				document.getElementById('txttopdesc').focus();
				return false;
			}
			if(max_item==''){
				alert('Please enter max item');
				document.getElementById('txtmax').focus();
				return false;
			}
			if(max_item<0){
				alert('Max item can not be a negative number');
				document.getElementById('txtmax').focus();
				return false;
			}
			if(isNaN(max_item)){
				alert('Please enter max item as number only');
				document.getElementById('txtmax').focus();
				return false;
			}
				document.forms[0].action=url_execute;
				document.forms[0].submit();
		}
		//-- UPDATE
		function updateTopic(url_execute){
			var top_name=document.getElementById('txttopname').value;
			var top_desc=document.getElementById('txttopdesc').value;
			var max_item=document.getElementById('txtmax').value;
			if(top_name==''){
				alert('Please enter topic name');
				document.getElementById('txttopname').focus();
				return false;
			}
			if(top_desc==''){
				alert('Please enter topic description');
				document.getElementById('txttopdesc').focus();
				return false;
			}
			if(max_item==''){
				alert('Please enter max item');
				document.getElementById('txtmax').focus();
				return false;
			}
			if(isNaN(max_item)){
				alert('Please enter max item as number only');
				document.getElementById('txtmax').focus();
				return false;
			}
				document.forms[0].action=url_execute;
				document.forms[0].submit();
		}
		
		
		function changeCategory(url_execute){
			document.forms[0].action=url_execute;
			document.forms[0].submit();
		}
		
		/-- VOTE EVENT--/
		// -- Add
		function addEvent(url_execute){
			var start_date=document.getElementById('datepicker1').value;
			var end_date=document.getElementById('datepicker2').value;
			if(start_date==''){
				alert('Please select start date');
				document.getElementById('datepicker1').focus();
				return false;
			}
			if(end_date==''){
				alert('Please select end date');
				document.getElementById('datepicker2').focus();
				return false;
			}
				document.forms[0].action=url_execute;
				document.forms[0].submit();
		}
		
		//-- DELETE
		function deleteEvent(url_execute){
				if(confirm("Are you sure you want to delete this event?")){
					window.location=url_execute;
				}else{
					return false;
				}
			}
		
		// -- Update
		function updateEvent(url_execute){
			var start_date=document.getElementById('datepicker1').value;
			var end_date=document.getElementById('datepicker2').value;
			if(start_date==''){
				alert('Please select start date');
				document.getElementById('datepicker1').focus();
				return false;
			}
			if(end_date==''){
				alert('Please select end date');
				document.getElementById('datepicker2').focus();
				return false;
			}
				document.forms[0].action=url_execute;
				document.forms[0].submit();
		}